package lumis.portal.presentation.tag.page;

import lumis.portal.channel.ChannelConfig;
import lumis.portal.presentation.core.HTMLFragmentComponent;
import lumis.portal.presentation.core.LayoutFilePage;
import lumis.portal.presentation.perspective.Perspective;
import lumis.util.XmlUtil;

import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.MarkupStream;

/**
 * Injects the page title.
 *
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
public class PageTitleComponent extends HTMLFragmentComponent 
{
	/**
	 * @since 6.0.0
	 */
	private static final long serialVersionUID = 1L;


	/**
	 * Creates a new RenderPortalStudioFooterComponent.
	 * @param id the component identifier.
	 * @param autoRenderBodyOnly if {@link #setRenderBodyOnly(boolean)} should
	 * automatically be set in case of layout file tags are to be stripped.
	 * @since 6.0.0
	 */
	public PageTitleComponent(String id) 
	{
		super(id, false);
	}

	@Override
	protected CharSequence getHTMLFragment(MarkupStream markupStream, ComponentTag openTag) 
	{
		LayoutFilePage page = (LayoutFilePage) getPage();
		
		if(Perspective.ADMIN.equals(page.getPortalMode().getPerspective()))
		{
			// output title according to the root channel
			if (page.getRootChannelId().equals(ChannelConfig.LUMIS_ADMIN_CHANNEL_ID))
				return "Lumis Portal Administration";
			else
				return "Lumis Portal Studio";
		}

		return XmlUtil.encodeXml( page.getPageWebResource().getPageWebResourceData().getTitle());
	}
}
